package de.openkanban.server.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import de.openkanban.server.interceptor.annotation.SecurityInterception;
import de.openkanban.server.service.KanbanService;
import de.openkanban.shared.dto.KanbanDto;
import de.openkanban.shared.dto.UserDto;

@Controller
@RequestMapping(value = "/kanban")
public class KanbanController {

	@Autowired
	private KanbanService kanbanService;

	@Autowired
	private DozerBeanMapper mapper;

	@RequestMapping(method = RequestMethod.POST, value = "/update")
	@ResponseBody
	@SecurityInterception
	public KanbanDto updateKanban(KanbanDto kanbanDto, HttpServletRequest req, HttpServletResponse resp) {				
		return mapper.map(kanbanService.updateKanban(kanbanDto), KanbanDto.class);
	}

	@RequestMapping(method = RequestMethod.POST, value = "{kanbanId}/user")
	@ResponseBody
	@SecurityInterception
	public UserDto[] getUser(@PathVariable Long kanbanId, HttpServletRequest req, HttpServletResponse resp) {
		return kanbanService.getUser(kanbanId);
	}
}